import Flutter
import UIKit
import CloudPushSDK
public class SwiftAliyunPushPlugin: NSObject, FlutterPlugin {
  public static func register(with registrar: FlutterPluginRegistrar) {
    let channel = FlutterMethodChannel(name: "aliyun_push", binaryMessenger: registrar.messenger())
    let instance = SwiftAliyunPushPlugin()
    registrar.addMethodCallDelegate(instance, channel: channel)
  }

  public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
    print("name is")
    result("iOS " + UIDevice.current.systemVersion)
  }
    /// 初始化阿里云移动推送组件
    func initCloudPush(_ launchOptions: [UIApplication.LaunchOptionsKey: Any]?) {
        
        /// 阿里云移动推送集成的时候会让你导入一个 plist 文件, 里面有阿里云推送所需数据 , 可以直接调用 autoInit 方法
        CloudPushSDK.autoInit { (result) in
            if result?.success == true {
                print("Init CloudPush Success, deviceId: \(String(describing: CloudPushSDK.getDeviceId()))")
            } else {
                print("Init CloudPush Failed, error: \(String(describing: result?.error))")
            }
        }
        
        CloudPushSDK.sendNotificationAck(launchOptions)
    }
}
